<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Aboutus extends CI_Controller {
	
	public function __construct() {
		
		parent::__construct();
		
		if (!$this->session->userdata('sessionAdmin'))
            redirect(base_url() . 'admin/login');
		
	}
	
	public function index() {

		$this->load->model('berita_model');
		
		$aboutus	= FALSE;
		$msg		= FALSE;
		
		if($this->input->post() == TRUE) {
			
			$this->form_validation->set_rules('isi', 'About Us', 'required');
			
			$id = $this->input->post('id');
				
			$params = array(
							'page'		=> 'aboutus',
							'judul'		=> '',
							'judul_url'	=> '',
							'synopsis'	=> '',
							'isi'		=> $this->input->post('isi'),
							'id'		=> $id
						);
			
			if($this->form_validation->run()) {
						
				$result = ($id == FALSE) ?
							$this->berita_model->insertBerita($params) :
							$this->berita_model->updateBeritaById($params) ;
							
				$msg = ($result == TRUE) ? 'Update berhasil' : 'Update gagal';
				
			}
			
			$aboutus = array('0' => $params);
			
		} else {
			
			$aboutus = $this->berita_model->getAboutus();
			
		}
		
		$data['aboutus']	= $aboutus;
		$data['msg']		= $msg;
		
		$data['template']['nav']		= "essential/admin_header";
		$data['template']['content']	= 'admin/aboutus';
		$data['template']['nosidebar']	= TRUE;
		
		$this->load->view ( 'essential/template', $data );
	}
} 